package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.common.Constants;
import com.chen.entity.Details;
import com.chen.entity.User;
import com.chen.exception.ServiceException;
import com.chen.mapper.DetailsMapper;
import com.chen.service.DetailsService;
import com.chen.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Y·C
 * @since 2023-04-20
 */
@Service
public class DetailsServiceImpl extends ServiceImpl<DetailsMapper, Details> implements DetailsService {

    @Autowired
    private DetailsMapper detailsMapper;

    @Override
    public void detailInfo(Details details) {
        User user = TokenUtils.getCurrentUser();
        details.setUid(user.getId());
        int i = detailsMapper.insert(details);
        if (i<1){
            throw new ServiceException(Constants.CODE_600, "填写失败");
        }
    }

    @Override
    public void updateDetailsInfo(Details details) {
        QueryWrapper<Details> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("uid",details.getUid());
        int i = detailsMapper.update(details,objectQueryWrapper);
        if (i<1){
            throw new ServiceException(Constants.CODE_600, "修改失败");
        }
    }


}
